DOI

https://doi.org/10.5281/zenodo.3635430

https://osf.io/3tjfk/

Histopathology Research Template 🔬


1 Introduction

  • State the marker of interest, the study objectives, and hypotheses (Knijn, Simmer, and Nagtegaal 2015).1

2 Materials & Methods

Describe Materials and Methods as highlighted in (Knijn, Simmer, and Nagtegaal 2015).2

  • Describe patient characteristics, and inclusion and exclusion criteria

  • Describe treatment details

  • Describe the type of material used

  • Specify how expression of the biomarker was assessed

  • Describe the number of independent (blinded) scorers and how they scored

  • State the method of case selection, study design, origin of the cases, and time frame

  • Describe the end of the follow-up period and median follow-up time

  • Define all clinical endpoints examined

  • Specify all applied statistical methods

  • Describe how interactions with other clinical/pathological factors were analyzed


2.1 Header Codes

Codes for general settings.3

Setup global chunk settings4

knitr::opts_chunk$set(
    eval = TRUE,
    echo = TRUE,
    fig.path = here::here("figs/"),
    message = FALSE,
    warning = FALSE,
    error = FALSE,
    cache = TRUE,
    comment = NA,
    tidy = TRUE,
    fig.width = 6,
    fig.height = 4
)

Load Library

see R/loadLibrary.R for the libraries loaded.

source(file = here::here("R", "loadLibrary.R"))

2.2 Generate Fake Data

Codes for generating fake data.5

Generate Fake Data

This code generates a fake histopathological data. Some sources for fake data generation here6 , here7 , here8 , here9 , here10 , here11 , here12 , here13 , and here14 .

Use this code to generate fake clinicopathologic data

source(file = here::here("R", "gc_fake_data.R"))
wakefield::table_heat(x = fakedata, palette = "Set1", flip = TRUE, print = TRUE)


2.3 Import Data

Codes for importing data.15

Read the data

library(readxl)
mydata <- readxl::read_excel(here::here("data", "mydata.xlsx"))
# View(mydata) # Use to view data after importing

Add code for import multiple data purrr reduce


2.4 Study Population

2.4.1 Report General Features

Codes for reporting general features.16

Dataframe Report

# Dataframe report
mydata %>% dplyr::select(-contains("Date")) %>% report::report(.)
The data contains 250 observations of the following variables:
  - ID: 250 entries: 001, n = 1; 002, n = 1; 003, n = 1 and 247 others (0 missing)
  - Name: 249 entries: Aaleyah, n = 1; Abrea, n = 1; Afonso, n = 1 and 246 others (1 missing)
  - Sex: 2 entries: Male, n = 127; Female, n = 122 (1 missing)
  - Age: Mean = 48.59, SD = 14.12, Median = , MAD = 17.79, range: [25, 73], Skewness = 0.07, Kurtosis = -1.17, 1 missing
  - Race: 7 entries: White, n = 151; Hispanic, n = 49; Black, n = 30 and 4 others (1 missing)
  - PreinvasiveComponent: 2 entries: Absent, n = 205; Present, n = 44 (1 missing)
  - LVI: 2 entries: Absent, n = 148; Present, n = 102 (0 missing)
  - PNI: 2 entries: Absent, n = 181; Present, n = 68 (1 missing)
  - Death: 2 levels: FALSE (n = 80, 32.00%); TRUE (n = 169, 67.60%) and missing (n = 1, 0.40%)
  - Group: 2 entries: Treatment, n = 130; Control, n = 119 (1 missing)
  - Grade: 3 entries: 3, n = 97; 2, n = 84; 1, n = 68 (1 missing)
  - TStage: 4 entries: 4, n = 113; 3, n = 65; 2, n = 49 and 1 other (0 missing)
  - AntiX_intensity: Mean = 2.39, SD = 0.66, Median = , MAD = 1.48, range: [1, 3], Skewness = -0.62, Kurtosis = -0.66, 1 missing
  - AntiY_intensity: Mean = 1.91, SD = 0.75, Median = , MAD = 1.48, range: [1, 3], Skewness = 0.15, Kurtosis = -1.20, 1 missing
  - LymphNodeMetastasis: 2 entries: Absent, n = 147; Present, n = 102 (1 missing)
  - Valid: 2 levels: FALSE (n = 134, 53.60%); TRUE (n = 115, 46.00%) and missing (n = 1, 0.40%)
  - Smoker: 2 levels: FALSE (n = 132, 52.80%); TRUE (n = 117, 46.80%) and missing (n = 1, 0.40%)
  - Grade_Level: 3 entries: high, n = 91; moderate, n = 83; low, n = 75 (1 missing)
  - DeathTime: 2 entries: Within1Year, n = 149; MoreThan1Year, n = 101 (0 missing)
mydata %>% explore::describe_tbl()
250 observations with 21 variables
17 variables containing missings (NA)
0 variables with no variance

2.5 Ethics and IRB

2.5.1 Always Respect Patient Privacy

Always Respect Patient Privacy
- Health Information Privacy17
- Kişisel Verilerin Korunması18


2.6 Define Variable Types

Codes for defining variable types.19

print column names as vector

dput(names(mydata))
c("ID", "Name", "Sex", "Age", "Race", "PreinvasiveComponent", 
"LVI", "PNI", "LastFollowUpDate", "Death", "Group", "Grade", 
"TStage", "AntiX_intensity", "AntiY_intensity", "LymphNodeMetastasis", 
"Valid", "Smoker", "Grade_Level", "SurgeryDate", "DeathTime")

2.6.1 Find Key Columns

2.6.1.1 Find ID and key columns to exclude from analysis

vctrs::vec_assert()

dplyr::all_equal()

arsenal::compare()

visdat::vis_compare()

See the code as function in R/find_key.R.

keycolumns <- mydata %>% sapply(., FUN = dataMaid::isKey) %>% tibble::as_tibble() %>% 
    dplyr::select(which(.[1, ] == TRUE)) %>% names()
keycolumns
[1] "ID"   "Name"

2.6.2 Variable Types

Get variable types

mydata %>% dplyr::select(-keycolumns) %>% inspectdf::inspect_types()
# A tibble: 4 x 4
  type             cnt  pcnt col_name  
  <chr>          <int> <dbl> <list>    
1 character         11  57.9 <chr [11]>
2 logical            3  15.8 <chr [3]> 
3 numeric            3  15.8 <chr [3]> 
4 POSIXct POSIXt     2  10.5 <chr [2]> 
mydata %>% dplyr::select(-keycolumns, -contains("Date")) %>% describer::describe() %>% 
    knitr::kable(format = "markdown")
.column_name .column_class .column_type .count_elements .mean_value .sd_value .q0_value .q25_value .q50_value .q75_value .q100_value
Sex character character 250 NA NA Female NA NA NA Male
Age numeric double 250 48.586345 14.1156504 25 36 48 61 73
Race character character 250 NA NA Asian NA NA NA White
PreinvasiveComponent character character 250 NA NA Absent NA NA NA Present
LVI character character 250 NA NA Absent NA NA NA Present
PNI character character 250 NA NA Absent NA NA NA Present
Death logical logical 250 NA NA FALSE NA NA NA TRUE
Group character character 250 NA NA Control NA NA NA Treatment
Grade character character 250 NA NA 1 NA NA NA 3
TStage character character 250 NA NA 1 NA NA NA 4
AntiX_intensity numeric double 250 2.385542 0.6629235 1 2 2 3 3
AntiY_intensity numeric double 250 1.907631 0.7483194 1 1 2 2 3
LymphNodeMetastasis character character 250 NA NA Absent NA NA NA Present
Valid logical logical 250 NA NA FALSE NA NA NA TRUE
Smoker logical logical 250 NA NA FALSE NA NA NA TRUE
Grade_Level character character 250 NA NA high NA NA NA moderate
DeathTime character character 250 NA NA MoreThan1Year NA NA NA Within1Year

Plot variable types

mydata %>% dplyr::select(-keycolumns) %>% inspectdf::inspect_types() %>% inspectdf::show_plot()

# https://github.com/ropensci/visdat
# http://visdat.njtierney.com/articles/using_visdat.html
# https://cran.r-project.org/web/packages/visdat/index.html
# http://visdat.njtierney.com/

# visdat::vis_guess(mydata)

visdat::vis_dat(mydata)

mydata %>% explore::explore_tbl()

2.6.3 Define Variable Types

2.6.3.1 Find character variables

characterVariables <- mydata %>% dplyr::select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "character") %>% dplyr::select(col_name) %>% dplyr::pull() %>% 
    unlist()

characterVariables
 [1] "Sex"                  "Race"                 "PreinvasiveComponent"
 [4] "LVI"                  "PNI"                  "Group"               
 [7] "Grade"                "TStage"               "LymphNodeMetastasis" 
[10] "Grade_Level"          "DeathTime"           

2.6.3.2 Find categorical variables

categoricalVariables <- mydata %>% dplyr::select(-keycolumns, -contains("Date")) %>% 
    describer::describe() %>% janitor::clean_names() %>% dplyr::filter(column_type == 
    "factor") %>% dplyr::select(column_name) %>% dplyr::pull()

categoricalVariables
character(0)

2.6.3.3 Find continious variables

continiousVariables <- mydata %>% dplyr::select(-keycolumns, -contains("Date")) %>% 
    describer::describe() %>% janitor::clean_names() %>% dplyr::filter(column_type == 
    "numeric" | column_type == "double") %>% dplyr::select(column_name) %>% dplyr::pull()

continiousVariables
[1] "Age"             "AntiX_intensity" "AntiY_intensity"

2.6.3.4 Find numeric variables

numericVariables <- mydata %>% dplyr::select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "numeric") %>% dplyr::select(col_name) %>% dplyr::pull() %>% 
    unlist()

numericVariables
[1] "Age"             "AntiX_intensity" "AntiY_intensity"

2.6.3.5 Find integer variables

integerVariables <- mydata %>% dplyr::select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "integer") %>% dplyr::select(col_name) %>% dplyr::pull() %>% 
    unlist()

integerVariables
NULL

2.6.3.6 Find list variables

listVariables <- mydata %>% dplyr::select(-keycolumns) %>% inspectdf::inspect_types() %>% 
    dplyr::filter(type == "list") %>% dplyr::select(col_name) %>% dplyr::pull() %>% 
    unlist()
listVariables
NULL

2.6.3.7 Find date variables

is_date <- function(x) inherits(x, c("POSIXct", "POSIXt"))

dateVariables <- names(which(sapply(mydata, FUN = is_date) == TRUE))
dateVariables
[1] "LastFollowUpDate" "SurgeryDate"     

2.7 Overview the Data

Codes for overviewing the data.20

2.7.1 View Data

View(mydata)
reactable::reactable(data = mydata, sortable = TRUE, resizable = TRUE, filterable = TRUE, 
    searchable = TRUE, pagination = TRUE, paginationType = "numbers", showPageSizeOptions = TRUE, 
    highlight = TRUE, striped = TRUE, outlined = TRUE, compact = TRUE, wrap = FALSE, 
    showSortIcon = TRUE, showSortable = TRUE)

2.7.2 Overview / Exploratory Data Analysis (EDA)

Summary of Data via summarytools 📦

summarytools::view(summarytools::dfSummary(mydata %>% dplyr::select(-keycolumns)))
if (!dir.exists(here::here("out"))) {
    dir.create(here::here("out"))
}

summarytools::view(x = summarytools::dfSummary(mydata %>% dplyr::select(-keycolumns)), 
    file = here::here("out", "mydata_summary.html"))

Summary via dataMaid 📦

if (!dir.exists(here::here("out"))) {
    dir.create(here::here("out"))
}

dataMaid::makeDataReport(data = mydata, file = here::here("out", "dataMaid_mydata.Rmd"), 
    replace = TRUE, openResult = FALSE, render = FALSE, quiet = TRUE)

Summary via explore 📦

if (!dir.exists(here::here("out"))) {
    dir.create(here::here("out"))
}

mydata %>% dplyr::select(-dateVariables) %>% explore::report(output_file = "mydata_report.html", 
    output_dir = here::here("out"))

Glimpse of Data

dplyr::glimpse(mydata %>% dplyr::select(-keycolumns, -dateVariables))
Observations: 250
Variables: 17
$ Sex                  <chr> "Female", "Female", "Female", "Female", "Male", …
$ Age                  <dbl> 54, 39, 32, 58, 38, 50, 36, 70, 43, 45, 65, 27, …
$ Race                 <chr> "White", "White", "White", "Hispanic", "White", …
$ PreinvasiveComponent <chr> "Present", "Absent", "Absent", "Present", "Prese…
$ LVI                  <chr> "Present", "Absent", "Present", "Absent", "Absen…
$ PNI                  <chr> "Absent", "Absent", "Absent", "Present", "Absent…
$ Death                <lgl> TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRU…
$ Group                <chr> "Treatment", "Treatment", "Control", "Treatment"…
$ Grade                <chr> "1", "3", "3", "3", "2", "1", "2", "2", "1", "3"…
$ TStage               <chr> "4", "4", "2", "1", "1", "4", "4", "4", "4", "1"…
$ AntiX_intensity      <dbl> 2, 3, 3, 3, 2, 2, 1, 3, 2, 2, 3, 2, 3, 1, 3, 3, …
$ AntiY_intensity      <dbl> 1, 1, 1, 1, 3, 3, 2, 3, 2, 2, 2, 1, 1, 2, 2, 2, …
$ LymphNodeMetastasis  <chr> "Present", "Absent", "Absent", "Absent", "Presen…
$ Valid                <lgl> FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, F…
$ Smoker               <lgl> FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TR…
$ Grade_Level          <chr> "low", "low", "moderate", "high", "high", "moder…
$ DeathTime            <chr> "Within1Year", "Within1Year", "Within1Year", "Wi…
mydata %>% explore::describe()
# A tibble: 21 x 8
   variable             type     na na_pct unique   min  mean   max
   <chr>                <chr> <int>  <dbl>  <int> <dbl> <dbl> <dbl>
 1 ID                   chr       0    0      250    NA NA       NA
 2 Name                 chr       1    0.4    250    NA NA       NA
 3 Sex                  chr       1    0.4      3    NA NA       NA
 4 Age                  dbl       1    0.4     50    25 48.6     73
 5 Race                 chr       1    0.4      8    NA NA       NA
 6 PreinvasiveComponent chr       1    0.4      3    NA NA       NA
 7 LVI                  chr       0    0        2    NA NA       NA
 8 PNI                  chr       1    0.4      3    NA NA       NA
 9 LastFollowUpDate     dat       1    0.4     13    NA NA       NA
10 Death                lgl       1    0.4      3     0  0.68     1
# … with 11 more rows

Explore

explore::explore(mydata)

2.7.3 Control Data

Control Data if matching expectations

visdat::vis_expect(data = mydata, expectation = ~.x == -1, show_perc = TRUE)

visdat::vis_expect(mydata, ~.x >= 25)

See missing values

visdat::vis_miss(airquality, cluster = TRUE)

visdat::vis_miss(airquality, sort_miss = TRUE)

xray::anomalies(mydata)
$variables
               Variable   q qNA  pNA qZero pZero qBlank pBlank qInf pInf
1                 Valid 250   1 0.4%   134 53.6%      0      -    0    -
2                Smoker 250   1 0.4%   132 52.8%      0      -    0    -
3                 Death 250   1 0.4%    80   32%      0      -    0    -
4                   Sex 250   1 0.4%     0     -      0      -    0    -
5  PreinvasiveComponent 250   1 0.4%     0     -      0      -    0    -
6                   PNI 250   1 0.4%     0     -      0      -    0    -
7                 Group 250   1 0.4%     0     -      0      -    0    -
8   LymphNodeMetastasis 250   1 0.4%     0     -      0      -    0    -
9                 Grade 250   1 0.4%     0     -      0      -    0    -
10      AntiX_intensity 250   1 0.4%     0     -      0      -    0    -
11      AntiY_intensity 250   1 0.4%     0     -      0      -    0    -
12          Grade_Level 250   1 0.4%     0     -      0      -    0    -
13                 Race 250   1 0.4%     0     -      0      -    0    -
14     LastFollowUpDate 250   1 0.4%     0     -      0      -    0    -
15                  Age 250   1 0.4%     0     -      0      -    0    -
16          SurgeryDate 250   1 0.4%     0     -      0      -    0    -
17                 Name 250   1 0.4%     0     -      0      -    0    -
18                  LVI 250   0    -     0     -      0      -    0    -
19            DeathTime 250   0    -     0     -      0      -    0    -
20               TStage 250   0    -     0     -      0      -    0    -
21                   ID 250   0    -     0     -      0      -    0    -
   qDistinct      type anomalous_percent
1          3   Logical               54%
2          3   Logical             53.2%
3          3   Logical             32.4%
4          3 Character              0.4%
5          3 Character              0.4%
6          3 Character              0.4%
7          3 Character              0.4%
8          3 Character              0.4%
9          4 Character              0.4%
10         4   Numeric              0.4%
11         4   Numeric              0.4%
12         4 Character              0.4%
13         8 Character              0.4%
14        13 Timestamp              0.4%
15        50   Numeric              0.4%
16       229 Timestamp              0.4%
17       250 Character              0.4%
18         2 Character                 -
19         2 Character                 -
20         4 Character                 -
21       250 Character                 -

$problem_variables
 [1] Variable          q                 qNA               pNA              
 [5] qZero             pZero             qBlank            pBlank           
 [9] qInf              pInf              qDistinct         type             
[13] anomalous_percent problems         
<0 rows> (or 0-length row.names)
xray::distributions(mydata)
================================================================================

[1] "Ignoring variable LastFollowUpDate: Unsupported type for visualization."
[1] "Ignoring variable SurgeryDate: Unsupported type for visualization."

         Variable p_1 p_10 p_25 p_50 p_75 p_90 p_99
1 AntiX_intensity   1  1.8    2    2    3    3    3
2 AntiY_intensity   1    1    1    2    2    3    3
3             Age  25 29.8   36   48   61 68.2   73

2.7.4 Explore Data

Summary of Data via DataExplorer 📦

DataExplorer::plot_str(mydata)
DataExplorer::plot_str(mydata, type = "r")
DataExplorer::introduce(mydata)
# A tibble: 1 x 9
   rows columns discrete_columns continuous_colu… all_missing_col…
  <int>   <int>            <int>            <int>            <int>
1   250      21               18                3                0
# … with 4 more variables: total_missing_values <int>, complete_rows <int>,
#   total_observations <int>, memory_usage <dbl>
DataExplorer::plot_intro(mydata)

DataExplorer::plot_missing(mydata)

Drop columns

mydata2 <- DataExplorer::drop_columns(mydata, "TStage")
DataExplorer::plot_bar(mydata)

DataExplorer::plot_bar(mydata, with = "Death")

DataExplorer::plot_histogram(mydata)



3 Statistical Analysis

Learn these tests as highlighted in (Schmidt et al. 2017).21


4 Results

Write results as described in (Knijn, Simmer, and Nagtegaal 2015)22

  • Describe the number of patients included in the analysis and reason for dropout

  • Report patient/disease characteristics (including the biomarker of interest) with the number of missing values

  • Describe the interaction of the biomarker of interest with established prognostic variables

  • Include at least 90 % of initial cases included in univariate and multivariate analyses

  • Report the estimated effect (relative risk/odds ratio, confidence interval, and p value) in univariate analysis

  • Report the estimated effect (hazard rate/odds ratio, confidence interval, and p value) in multivariate analysis

  • Report the estimated effects (hazard ratio/odds ratio, confidence interval, and p value) of other prognostic factors included in multivariate analysis


4.1 Descriptive Statistics

Codes for Descriptive Statistics.23

4.1.1 Table One

Report Data properties via report 📦

mydata %>% dplyr::select(-dplyr::contains("Date")) %>% report::report()
The data contains 250 observations of the following variables:
  - ID: 250 entries: 001, n = 1; 002, n = 1; 003, n = 1 and 247 others (0 missing)
  - Name: 249 entries: Aaleyah, n = 1; Abrea, n = 1; Afonso, n = 1 and 246 others (1 missing)
  - Sex: 2 entries: Male, n = 127; Female, n = 122 (1 missing)
  - Age: Mean = 48.59, SD = 14.12, Median = , MAD = 17.79, range: [25, 73], Skewness = 0.07, Kurtosis = -1.17, 1 missing
  - Race: 7 entries: White, n = 151; Hispanic, n = 49; Black, n = 30 and 4 others (1 missing)
  - PreinvasiveComponent: 2 entries: Absent, n = 205; Present, n = 44 (1 missing)
  - LVI: 2 entries: Absent, n = 148; Present, n = 102 (0 missing)
  - PNI: 2 entries: Absent, n = 181; Present, n = 68 (1 missing)
  - Death: 2 levels: FALSE (n = 80, 32.00%); TRUE (n = 169, 67.60%) and missing (n = 1, 0.40%)
  - Group: 2 entries: Treatment, n = 130; Control, n = 119 (1 missing)
  - Grade: 3 entries: 3, n = 97; 2, n = 84; 1, n = 68 (1 missing)
  - TStage: 4 entries: 4, n = 113; 3, n = 65; 2, n = 49 and 1 other (0 missing)
  - AntiX_intensity: Mean = 2.39, SD = 0.66, Median = , MAD = 1.48, range: [1, 3], Skewness = -0.62, Kurtosis = -0.66, 1 missing
  - AntiY_intensity: Mean = 1.91, SD = 0.75, Median = , MAD = 1.48, range: [1, 3], Skewness = 0.15, Kurtosis = -1.20, 1 missing
  - LymphNodeMetastasis: 2 entries: Absent, n = 147; Present, n = 102 (1 missing)
  - Valid: 2 levels: FALSE (n = 134, 53.60%); TRUE (n = 115, 46.00%) and missing (n = 1, 0.40%)
  - Smoker: 2 levels: FALSE (n = 132, 52.80%); TRUE (n = 117, 46.80%) and missing (n = 1, 0.40%)
  - Grade_Level: 3 entries: high, n = 91; moderate, n = 83; low, n = 75 (1 missing)
  - DeathTime: 2 entries: Within1Year, n = 149; MoreThan1Year, n = 101 (0 missing)

Table 1 via arsenal 📦

# cat(names(mydata), sep = " + \n")
library(arsenal)
tab1 <- arsenal::tableby(
  ~ Sex +
    Age +
    Race +
    PreinvasiveComponent +
    LVI +
    PNI +
    Death +
    Group +
    Grade +
    TStage +
    # `Anti-X-intensity` +
    # `Anti-Y-intensity` +
    LymphNodeMetastasis +
    Valid +
    Smoker +
    Grade_Level
  ,
  data = mydata 
)
summary(tab1)
Overall (N=250)
Sex
   N-Miss 1
   Female 122 (49.0%)
   Male 127 (51.0%)
Age
   N-Miss 1
   Mean (SD) 48.586 (14.116)
   Range 25.000 - 73.000
Race
   N-Miss 1
   Asian 11 (4.4%)
   Bi-Racial 5 (2.0%)
   Black 30 (12.0%)
   Hispanic 49 (19.7%)
   Native 1 (0.4%)
   Other 2 (0.8%)
   White 151 (60.6%)
PreinvasiveComponent
   N-Miss 1
   Absent 205 (82.3%)
   Present 44 (17.7%)
LVI
   Absent 148 (59.2%)
   Present 102 (40.8%)
PNI
   N-Miss 1
   Absent 181 (72.7%)
   Present 68 (27.3%)
Death
   N-Miss 1
   FALSE 80 (32.1%)
   TRUE 169 (67.9%)
Group
   N-Miss 1
   Control 119 (47.8%)
   Treatment 130 (52.2%)
Grade
   N-Miss 1
   1 68 (27.3%)
   2 84 (33.7%)
   3 97 (39.0%)
TStage
   1 23 (9.2%)
   2 49 (19.6%)
   3 65 (26.0%)
   4 113 (45.2%)
LymphNodeMetastasis
   N-Miss 1
   Absent 147 (59.0%)
   Present 102 (41.0%)
Valid
   N-Miss 1
   FALSE 134 (53.8%)
   TRUE 115 (46.2%)
Smoker
   N-Miss 1
   FALSE 132 (53.0%)
   TRUE 117 (47.0%)
Grade_Level
   N-Miss 1
   high 91 (36.5%)
   low 75 (30.1%)
   moderate 83 (33.3%)

Table 1 via tableone 📦

library(tableone)
mydata %>% dplyr::select(-keycolumns, -dateVariables) %>% tableone::CreateTableOne(data = .)
                                    
                                     Overall      
  n                                    250        
  Sex = Male (%)                       127 (51.0) 
  Age (mean (SD))                    48.59 (14.12)
  Race (%)                                        
     Asian                              11 ( 4.4) 
     Bi-Racial                           5 ( 2.0) 
     Black                              30 (12.0) 
     Hispanic                           49 (19.7) 
     Native                              1 ( 0.4) 
     Other                               2 ( 0.8) 
     White                             151 (60.6) 
  PreinvasiveComponent = Present (%)    44 (17.7) 
  LVI = Present (%)                    102 (40.8) 
  PNI = Present (%)                     68 (27.3) 
  Death = TRUE (%)                     169 (67.9) 
  Group = Treatment (%)                130 (52.2) 
  Grade (%)                                       
     1                                  68 (27.3) 
     2                                  84 (33.7) 
     3                                  97 (39.0) 
  TStage (%)                                      
     1                                  23 ( 9.2) 
     2                                  49 (19.6) 
     3                                  65 (26.0) 
     4                                 113 (45.2) 
  AntiX_intensity (mean (SD))         2.39 (0.66) 
  AntiY_intensity (mean (SD))         1.91 (0.75) 
  LymphNodeMetastasis = Present (%)    102 (41.0) 
  Valid = TRUE (%)                     115 (46.2) 
  Smoker = TRUE (%)                    117 (47.0) 
  Grade_Level (%)                                 
     high                               91 (36.5) 
     low                                75 (30.1) 
     moderate                           83 (33.3) 
  DeathTime = Within1Year (%)          149 (59.6) 

Descriptive Statistics of Continuous Variables

mydata %>% dplyr::select(continiousVariables, numericVariables, integerVariables) %>% 
    summarytools::descr(., style = "rmarkdown")
print(summarytools::descr(mydata), method = "render", table.classes = "st-small")
mydata %>% summarytools::descr(., stats = "common", transpose = TRUE, headings = FALSE)
mydata %>% summarytools::descr(stats = "common") %>% summarytools::tb()
mydata$Sex %>% summarytools::freq(cumul = FALSE, report.nas = FALSE) %>% summarytools::tb()
mydata %>% explore::describe() %>% dplyr::filter(unique < 5)
# A tibble: 15 x 8
   variable             type     na na_pct unique   min  mean   max
   <chr>                <chr> <int>  <dbl>  <int> <dbl> <dbl> <dbl>
 1 Sex                  chr       1    0.4      3    NA NA       NA
 2 PreinvasiveComponent chr       1    0.4      3    NA NA       NA
 3 LVI                  chr       0    0        2    NA NA       NA
 4 PNI                  chr       1    0.4      3    NA NA       NA
 5 Death                lgl       1    0.4      3     0  0.68     1
 6 Group                chr       1    0.4      3    NA NA       NA
 7 Grade                chr       1    0.4      4    NA NA       NA
 8 TStage               chr       0    0        4    NA NA       NA
 9 AntiX_intensity      dbl       1    0.4      4     1  2.39     3
10 AntiY_intensity      dbl       1    0.4      4     1  1.91     3
11 LymphNodeMetastasis  chr       1    0.4      3    NA NA       NA
12 Valid                lgl       1    0.4      3     0  0.46     1
13 Smoker               lgl       1    0.4      3     0  0.47     1
14 Grade_Level          chr       1    0.4      4    NA NA       NA
15 DeathTime            chr       0    0        2    NA NA       NA
mydata %>% explore::describe() %>% dplyr::filter(na > 0)
# A tibble: 17 x 8
   variable             type     na na_pct unique   min  mean   max
   <chr>                <chr> <int>  <dbl>  <int> <dbl> <dbl> <dbl>
 1 Name                 chr       1    0.4    250    NA NA       NA
 2 Sex                  chr       1    0.4      3    NA NA       NA
 3 Age                  dbl       1    0.4     50    25 48.6     73
 4 Race                 chr       1    0.4      8    NA NA       NA
 5 PreinvasiveComponent chr       1    0.4      3    NA NA       NA
 6 PNI                  chr       1    0.4      3    NA NA       NA
 7 LastFollowUpDate     dat       1    0.4     13    NA NA       NA
 8 Death                lgl       1    0.4      3     0  0.68     1
 9 Group                chr       1    0.4      3    NA NA       NA
10 Grade                chr       1    0.4      4    NA NA       NA
11 AntiX_intensity      dbl       1    0.4      4     1  2.39     3
12 AntiY_intensity      dbl       1    0.4      4     1  1.91     3
13 LymphNodeMetastasis  chr       1    0.4      3    NA NA       NA
14 Valid                lgl       1    0.4      3     0  0.46     1
15 Smoker               lgl       1    0.4      3     0  0.47     1
16 Grade_Level          chr       1    0.4      4    NA NA       NA
17 SurgeryDate          dat       1    0.4    229    NA NA       NA
mydata %>% explore::describe()
# A tibble: 21 x 8
   variable             type     na na_pct unique   min  mean   max
   <chr>                <chr> <int>  <dbl>  <int> <dbl> <dbl> <dbl>
 1 ID                   chr       0    0      250    NA NA       NA
 2 Name                 chr       1    0.4    250    NA NA       NA
 3 Sex                  chr       1    0.4      3    NA NA       NA
 4 Age                  dbl       1    0.4     50    25 48.6     73
 5 Race                 chr       1    0.4      8    NA NA       NA
 6 PreinvasiveComponent chr       1    0.4      3    NA NA       NA
 7 LVI                  chr       0    0        2    NA NA       NA
 8 PNI                  chr       1    0.4      3    NA NA       NA
 9 LastFollowUpDate     dat       1    0.4     13    NA NA       NA
10 Death                lgl       1    0.4      3     0  0.68     1
# … with 11 more rows

4.1.2 Categorical Variables

Use R/gc_desc_cat.R to generate gc_desc_cat.Rmd containing descriptive statistics for categorical variables

source(here::here("R", "gc_desc_cat.R"))

4.1.2.1 Descriptive Statistics Sex

mydata %>% janitor::tabyl(Sex) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Sex n percent valid_percent
Female 122 48.8% 49.0%
Male 127 50.8% 51.0%
NA 1 0.4% -

4.1.2.2 Descriptive Statistics Race

mydata %>% janitor::tabyl(Race) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Race n percent valid_percent
Asian 11 4.4% 4.4%
Bi-Racial 5 2.0% 2.0%
Black 30 12.0% 12.0%
Hispanic 49 19.6% 19.7%
Native 1 0.4% 0.4%
Other 2 0.8% 0.8%
White 151 60.4% 60.6%
NA 1 0.4% -

4.1.2.3 Descriptive Statistics PreinvasiveComponent

mydata %>% janitor::tabyl(PreinvasiveComponent) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
PreinvasiveComponent n percent valid_percent
Absent 205 82.0% 82.3%
Present 44 17.6% 17.7%
NA 1 0.4% -

4.1.2.4 Descriptive Statistics LVI

mydata %>% janitor::tabyl(LVI) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
LVI n percent
Absent 148 59.2%
Present 102 40.8%

4.1.2.5 Descriptive Statistics PNI

mydata %>% janitor::tabyl(PNI) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
PNI n percent valid_percent
Absent 181 72.4% 72.7%
Present 68 27.2% 27.3%
NA 1 0.4% -

4.1.2.6 Descriptive Statistics Group

mydata %>% janitor::tabyl(Group) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Group n percent valid_percent
Control 119 47.6% 47.8%
Treatment 130 52.0% 52.2%
NA 1 0.4% -

4.1.2.7 Descriptive Statistics Grade

mydata %>% janitor::tabyl(Grade) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Grade n percent valid_percent
1 68 27.2% 27.3%
2 84 33.6% 33.7%
3 97 38.8% 39.0%
NA 1 0.4% -

4.1.2.8 Descriptive Statistics TStage

mydata %>% janitor::tabyl(TStage) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
TStage n percent
1 23 9.2%
2 49 19.6%
3 65 26.0%
4 113 45.2%

4.1.2.9 Descriptive Statistics LymphNodeMetastasis

mydata %>% janitor::tabyl(LymphNodeMetastasis) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
LymphNodeMetastasis n percent valid_percent
Absent 147 58.8% 59.0%
Present 102 40.8% 41.0%
NA 1 0.4% -

4.1.2.10 Descriptive Statistics Grade_Level

mydata %>% janitor::tabyl(Grade_Level) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
Grade_Level n percent valid_percent
high 91 36.4% 36.5%
low 75 30.0% 30.1%
moderate 83 33.2% 33.3%
NA 1 0.4% -

4.1.2.11 Descriptive Statistics DeathTime

mydata %>% janitor::tabyl(DeathTime) %>% janitor::adorn_pct_formatting(rounding = "half up", 
    digits = 1) %>% knitr::kable()
DeathTime n percent
MoreThan1Year 101 40.4%
Within1Year 149 59.6%
race_stats <- summarytools::freq(mydata$Race)
print(race_stats, report.nas = FALSE, totals = FALSE, display.type = FALSE, Variable.label = "Race Group")
mydata %>% explore::describe(PreinvasiveComponent)
variable = PreinvasiveComponent
type     = character
na       = 1 of 250 (0.4%)
unique   = 3
 Absent  = 205 (82%)
 Present = 44 (17.6%)
 NA      = 1 (0.4%)
## Frequency or custom tables for categorical variables
SmartEDA::ExpCTable(mydata, Target = NULL, margin = 1, clim = 10, nlim = 5, round = 2, 
    bin = NULL, per = T)
               Variable         Valid Frequency Percent CumPercent
1                   Sex        Female       122    48.8       48.8
2                   Sex          Male       127    50.8       99.6
3                   Sex            NA         1     0.4      100.0
4                   Sex         TOTAL       250      NA         NA
5                  Race         Asian        11     4.4        4.4
6                  Race     Bi-Racial         5     2.0        6.4
7                  Race         Black        30    12.0       18.4
8                  Race      Hispanic        49    19.6       38.0
9                  Race            NA         1     0.4       38.4
10                 Race        Native         1     0.4       38.8
11                 Race         Other         2     0.8       39.6
12                 Race         White       151    60.4      100.0
13                 Race         TOTAL       250      NA         NA
14 PreinvasiveComponent        Absent       205    82.0       82.0
15 PreinvasiveComponent            NA         1     0.4       82.4
16 PreinvasiveComponent       Present        44    17.6      100.0
17 PreinvasiveComponent         TOTAL       250      NA         NA
18                  LVI        Absent       148    59.2       59.2
19                  LVI       Present       102    40.8      100.0
20                  LVI         TOTAL       250      NA         NA
21                  PNI        Absent       181    72.4       72.4
22                  PNI            NA         1     0.4       72.8
23                  PNI       Present        68    27.2      100.0
24                  PNI         TOTAL       250      NA         NA
25                Group       Control       119    47.6       47.6
26                Group            NA         1     0.4       48.0
27                Group     Treatment       130    52.0      100.0
28                Group         TOTAL       250      NA         NA
29                Grade             1        68    27.2       27.2
30                Grade             2        84    33.6       60.8
31                Grade             3        97    38.8       99.6
32                Grade            NA         1     0.4      100.0
33                Grade         TOTAL       250      NA         NA
34               TStage             1        23     9.2        9.2
35               TStage             2        49    19.6       28.8
36               TStage             3        65    26.0       54.8
37               TStage             4       113    45.2      100.0
38               TStage         TOTAL       250      NA         NA
39  LymphNodeMetastasis        Absent       147    58.8       58.8
40  LymphNodeMetastasis            NA         1     0.4       59.2
41  LymphNodeMetastasis       Present       102    40.8      100.0
42  LymphNodeMetastasis         TOTAL       250      NA         NA
43          Grade_Level          high        91    36.4       36.4
44          Grade_Level           low        75    30.0       66.4
45          Grade_Level      moderate        83    33.2       99.6
46          Grade_Level            NA         1     0.4      100.0
47          Grade_Level         TOTAL       250      NA         NA
48            DeathTime MoreThan1Year       101    40.4       40.4
49            DeathTime   Within1Year       149    59.6      100.0
50            DeathTime         TOTAL       250      NA         NA
51      AntiX_intensity             1        25    10.0       10.0
52      AntiX_intensity             2       103    41.2       51.2
53      AntiX_intensity             3       121    48.4       99.6
54      AntiX_intensity            NA         1     0.4      100.0
55      AntiX_intensity         TOTAL       250      NA         NA
56      AntiY_intensity             1        82    32.8       32.8
57      AntiY_intensity             2       108    43.2       76.0
58      AntiY_intensity             3        59    23.6       99.6
59      AntiY_intensity            NA         1     0.4      100.0
60      AntiY_intensity         TOTAL       250      NA         NA
inspectdf::inspect_cat(mydata)
# A tibble: 16 x 5
   col_name               cnt common      common_pcnt levels            
   <chr>                <int> <chr>             <dbl> <named list>      
 1 Death                    3 TRUE               67.6 <tibble [3 × 3]>  
 2 DeathTime                2 Within1Year        59.6 <tibble [2 × 3]>  
 3 Grade                    4 3                  38.8 <tibble [4 × 3]>  
 4 Grade_Level              4 high               36.4 <tibble [4 × 3]>  
 5 Group                    3 Treatment          52   <tibble [3 × 3]>  
 6 ID                     250 001                 0.4 <tibble [250 × 3]>
 7 LVI                      2 Absent             59.2 <tibble [2 × 3]>  
 8 LymphNodeMetastasis      3 Absent             58.8 <tibble [3 × 3]>  
 9 Name                   250 Aaleyah             0.4 <tibble [250 × 3]>
10 PNI                      3 Absent             72.4 <tibble [3 × 3]>  
11 PreinvasiveComponent     3 Absent             82   <tibble [3 × 3]>  
12 Race                     8 White              60.4 <tibble [8 × 3]>  
13 Sex                      3 Male               50.8 <tibble [3 × 3]>  
14 Smoker                   3 FALSE              52.8 <tibble [3 × 3]>  
15 TStage                   4 4                  45.2 <tibble [4 × 3]>  
16 Valid                    3 FALSE              53.6 <tibble [3 × 3]>  
inspectdf::inspect_cat(mydata)$levels$Group
# A tibble: 3 x 3
  value      prop   cnt
  <chr>     <dbl> <int>
1 Treatment 0.52    130
2 Control   0.476   119
3 <NA>      0.004     1

4.1.2.12 Split-Group Stats Categorical

library(summarytools)

grouped_freqs <- stby(data = mydata$Smoker, INDICES = mydata$Sex, FUN = freq, cumul = FALSE, 
    report.nas = FALSE)

grouped_freqs %>% tb(order = 2)

4.1.2.13 Grouped Categorical

summarytools::stby(list(x = mydata$LVI, y = mydata$LymphNodeMetastasis), mydata$PNI, 
    summarytools::ctable)
with(mydata, summarytools::stby(list(x = LVI, y = LymphNodeMetastasis), PNI, summarytools::ctable))
mydata %>% dplyr::select(characterVariables) %>% dplyr::select(PreinvasiveComponent, 
    PNI, LVI) %>% reactable::reactable(data = ., groupBy = c("PreinvasiveComponent", 
    "PNI"), columns = list(LVI = reactable::colDef(aggregate = "count")))

4.1.3 Continious Variables

questionr:::icut()
source(here::here("R", "gc_desc_cont.R"))

Descriptive Statistics Age

mydata %>% jmv::descriptives(data = ., vars = "Age", hist = TRUE, dens = TRUE, box = TRUE, 
    violin = TRUE, dot = TRUE, mode = TRUE, sd = TRUE, variance = TRUE, skew = TRUE, 
    kurt = TRUE, quart = TRUE)

 DESCRIPTIVES

 Descriptives                      
 ───────────────────────────────── 
                          Age      
 ───────────────────────────────── 
   N                         249   
   Missing                     1   
   Mean                     48.6   
   Median                   48.0   
   Mode                     48.0   
   Standard deviation       14.1   
   Variance                  199   
   Minimum                  25.0   
   Maximum                  73.0   
   Skewness               0.0724   
   Std. error skewness     0.154   
   Kurtosis                -1.17   
   Std. error kurtosis     0.307   
   25th percentile          36.0   
   50th percentile          48.0   
   75th percentile          61.0   
 ───────────────────────────────── 

Descriptive Statistics AntiX_intensity

mydata %>% jmv::descriptives(data = ., vars = "AntiX_intensity", hist = TRUE, dens = TRUE, 
    box = TRUE, violin = TRUE, dot = TRUE, mode = TRUE, sd = TRUE, variance = TRUE, 
    skew = TRUE, kurt = TRUE, quart = TRUE)

 DESCRIPTIVES

 Descriptives                               
 ────────────────────────────────────────── 
                          AntiX_intensity   
 ────────────────────────────────────────── 
   N                                  249   
   Missing                              1   
   Mean                              2.39   
   Median                            2.00   
   Mode                              3.00   
   Standard deviation               0.663   
   Variance                         0.439   
   Minimum                           1.00   
   Maximum                           3.00   
   Skewness                        -0.618   
   Std. error skewness              0.154   
   Kurtosis                        -0.648   
   Std. error kurtosis              0.307   
   25th percentile                   2.00   
   50th percentile                   2.00   
   75th percentile                   3.00   
 ────────────────────────────────────────── 

Descriptive Statistics AntiY_intensity

mydata %>% jmv::descriptives(data = ., vars = "AntiY_intensity", hist = TRUE, dens = TRUE, 
    box = TRUE, violin = TRUE, dot = TRUE, mode = TRUE, sd = TRUE, variance = TRUE, 
    skew = TRUE, kurt = TRUE, quart = TRUE)

 DESCRIPTIVES

 Descriptives                               
 ────────────────────────────────────────── 
                          AntiY_intensity   
 ────────────────────────────────────────── 
   N                                  249   
   Missing                              1   
   Mean                              1.91   
   Median                            2.00   
   Mode                              2.00   
   Standard deviation               0.748   
   Variance                         0.560   
   Minimum                           1.00   
   Maximum                           3.00   
   Skewness                         0.152   
   Std. error skewness              0.154   
   Kurtosis                         -1.20   
   Std. error kurtosis              0.307   
   25th percentile                   1.00   
   50th percentile                   2.00   
   75th percentile                   2.00   
 ────────────────────────────────────────── 

tab <- tableone::CreateTableOne(data = mydata)
# ?print.ContTable
tab$ContTable
                             
                              Overall      
  n                           250          
  Age (mean (SD))             48.59 (14.12)
  AntiX_intensity (mean (SD))  2.39 (0.66) 
  AntiY_intensity (mean (SD))  1.91 (0.75) 
print(tab$ContTable, nonnormal = c("Anti-X-intensity"))
                             
                              Overall      
  n                           250          
  Age (mean (SD))             48.59 (14.12)
  AntiX_intensity (mean (SD))  2.39 (0.66) 
  AntiY_intensity (mean (SD))  1.91 (0.75) 
mydata %>% explore::describe(Age)
variable = Age
type     = double
na       = 1 of 250 (0.4%)
unique   = 50
min|max  = 25 | 73
q05|q95  = 27.4 | 71
q25|q75  = 36 | 61
median   = 48
mean     = 48.58635
mydata %>% dplyr::select(continiousVariables) %>% SmartEDA::ExpNumStat(data = ., 
    by = "A", gp = NULL, Qnt = seq(0, 1, 0.1), MesofShape = 2, Outlier = TRUE, round = 2)
inspectdf::inspect_num(mydata, breaks = 10)
# A tibble: 3 x 10
  col_name        min    q1 median  mean    q3   max     sd pcnt_na hist        
  <chr>         <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl>  <dbl>   <dbl> <named list>
1 Age              25    36     48 48.6     61    73 14.1       0.4 <tibble [12…
2 AntiX_intens…     1     2      2  2.39     3     3  0.663     0.4 <tibble [12…
3 AntiY_intens…     1     1      2  1.91     2     3  0.748     0.4 <tibble [12…
inspectdf::inspect_num(mydata)$hist$Age
# A tibble: 27 x 2
   value        prop
   <chr>       <dbl>
 1 [-Inf, 24) 0     
 2 [24, 26)   0.0241
 3 [26, 28)   0.0281
 4 [28, 30)   0.0482
 5 [30, 32)   0.0402
 6 [32, 34)   0.0562
 7 [34, 36)   0.0402
 8 [36, 38)   0.0402
 9 [38, 40)   0.0321
10 [40, 42)   0.0402
# … with 17 more rows
inspectdf::inspect_num(mydata, breaks = 10) %>% inspectdf::show_plot()

4.1.3.1 Split-Group Stats Continious

grouped_descr <- summarytools::stby(data = mydata, INDICES = mydata$Sex, FUN = summarytools::descr, 
    stats = "common")
# grouped_descr %>% summarytools::tb(order = 2)
grouped_descr %>% summarytools::tb()

4.1.3.2 Grouped Continious

summarytools::stby(data = mydata, INDICES = mydata$PreinvasiveComponent, FUN = summarytools::descr, 
    stats = c("mean", "sd", "min", "med", "max"), transpose = TRUE)
with(mydata, summarytools::stby(Age, PreinvasiveComponent, summarytools::descr), 
    stats = c("mean", "sd", "min", "med", "max"), transpose = TRUE)
mydata %>% group_by(PreinvasiveComponent) %>% summarytools::descr(stats = "fivenum")
## Summary statistics by – category
SmartEDA::ExpNumStat(mydata, by = "GA", gp = "PreinvasiveComponent", Qnt = seq(0, 
    1, 0.1), MesofShape = 2, Outlier = TRUE, round = 2)
  Vname                        Group  TN nNeg nZero nPos NegInf PosInf NA_Value
1   Age     PreinvasiveComponent:All 250    0     0  249      0      0        1
2   Age PreinvasiveComponent:Present  44    0     0   44      0      0        0
3   Age  PreinvasiveComponent:Absent 205    0     0  204      0      0        1
4   Age      PreinvasiveComponent:NA   0    0     0    0      0      0        0
  Per_of_Missing   sum min  max  mean median    SD   CV   IQR Skewness Kurtosis
1           0.40 12098  25   73 48.59   48.0 14.12 0.29 25.00     0.07    -1.17
2           0.00  2144  25   73 48.73   48.5 15.11 0.31 27.75    -0.05    -1.26
3           0.49  9910  25   73 48.58   48.0 13.96 0.29 25.00     0.10    -1.16
4            NaN     0 Inf -Inf   NaN     NA    NA   NA    NA      NaN      NaN
  0%  10%  20%  30% 40%  50%  60%  70% 80%  90% 100% LB.25% UB.75% nOutliers
1 25 29.8 34.0 39.0  44 48.0 53.0 58.0  64 68.2   73  -1.50  98.50         0
2 25 29.0 30.6 40.0  45 48.5 54.0 58.3  64 69.4   73  -5.38 105.62         0
3 25 31.0 34.0 38.9  44 48.0 52.8 58.0  63 68.0   73  -1.50  98.50         0
4 NA   NA   NA   NA  NA   NA   NA   NA  NA   NA   NA     NA     NA         0

4.2 Cross Tables

Codes for cross tables.24

library(finalfit)
dependent <- c("dependent1", "dependent2")

explanatory <- c("explanatory1", "explanatory2")

dependent <- "PreinvasiveComponent"

explanatory <- c("Sex", "Age", "Grade", "TStage")

Change column = TRUE argument to get row or column percentages.

source(here::here("R", "gc_table_cross.R"))

Cross Table PreinvasiveComponent

mydata %>%
    summary_factorlist(dependent = 'PreinvasiveComponent', 
                       explanatory = explanatory,
                       # column = TRUE,
                       total_col = TRUE,
                       p = TRUE,
                       add_dependent_label = TRUE,
                       na_include=FALSE
                       # catTest = catTestfisher
                       ) -> table

knitr::kable(table, row.names = FALSE, align = c('l', 'l', 'r', 'r', 'r'))
Dependent: PreinvasiveComponent Absent Present Total p
Sex Female 101 (49.5) 20 (45.5) 121 (48.8) 0.625
Male 103 (50.5) 24 (54.5) 127 (51.2)
Age Mean (SD) 48.6 (14.0) 48.7 (15.1) 48.6 (14.1) 0.997
Grade 1 53 (25.9) 15 (34.9) 68 (27.4) 0.453
2 71 (34.6) 12 (27.9) 83 (33.5)
3 81 (39.5) 16 (37.2) 97 (39.1)
TStage 1 18 (8.8) 5 (11.4) 23 (9.2) 0.934
2 41 (20.0) 8 (18.2) 49 (19.7)
3 52 (25.4) 12 (27.3) 64 (25.7)
4 94 (45.9) 19 (43.2) 113 (45.4)
library(DT)
datatable(mtcars, rownames = FALSE, filter="top", options = list(pageLength = 5, scrollX=T) )

4.3 Survival Analysis

Codes for Survival Analysis25

  • Survival analysis with strata, clusters, frailties and competing risks in in Finalfit

https://www.datasurg.net/2019/09/12/survival-analysis-with-strata-clusters-frailties-and-competing-risks-in-in-finalfit/

  • Intracranial WHO grade I meningioma: a competing risk analysis of progression and disease-specific survival

https://link.springer.com/article/10.1007/s00701-019-04096-9

Calculate survival time

mydata$int <- lubridate::interval(lubridate::ymd(mydata$SurgeryDate), lubridate::ymd(mydata$LastFollowUpDate))
mydata$OverallTime <- lubridate::time_length(mydata$int, "month")
mydata$OverallTime <- round(mydata$OverallTime, digits = 1)

recode death status outcome as numbers for survival analysis

## Recoding mydata$Death into mydata$Outcome
mydata$Outcome <- forcats::fct_recode(as.character(mydata$Death), `1` = "TRUE", `0` = "FALSE")
mydata$Outcome <- as.numeric(as.character(mydata$Outcome))

it is always a good practice to double-check after recoding26

table(mydata$Death, mydata$Outcome)
       
          0   1
  FALSE  80   0
  TRUE    0 169

4.3.1 Kaplan-Meier

library(survival)
# data(lung) km <- with(lung, Surv(time, status))
km <- with(mydata, Surv(OverallTime, Outcome))
head(km, 80)
 [1] 10.5   9.1   7.1+  8.0   5.8   8.2+  8.8+  9.3   9.0  10.5+  3.4+  8.7 
[13]  3.8   5.6   8.1   8.9   8.1   8.9   7.7+  5.2+ 10.5   4.0   7.2   5.2+
[25]  4.2   3.3   4.0   4.0+ 11.0  10.7+  7.3+ 11.4+  6.4   8.7    NA+  6.9+
[37]  5.9  10.5+  8.8   8.2  11.5+  7.0   6.4   9.6   5.6+  9.9+  8.2+  9.1 
[49]  3.3  11.6   7.3+ 10.8   7.6  11.5   4.0+  8.1+ 10.4+  6.2+  9.6   6.5 
[61] 11.8+  4.1   6.6   5.8+  9.3+  5.4   7.1   9.6   3.9   4.9   3.3   9.0 
[73]  5.8   9.3   5.2   8.3  10.3  10.6   7.1+  6.4 
plot(km)

Kaplan-Meier Plot Log-Rank Test

# Drawing Survival Curves Using ggplot2
# https://rpkgs.datanovia.com/survminer/reference/ggsurvplot.html
dependentKM <- "Surv(OverallTime, Outcome)"
explanatoryKM <- "LVI"

mydata %>%
  finalfit::surv_plot(.data = .,
                      dependent = dependentKM,
                      explanatory = explanatoryKM,
                      xlab='Time (months)',
                      pval=TRUE,
                      legend = 'none',
                      break.time.by = 12,
                      xlim = c(0,60)
                      # legend.labs = c('a','b')
                      )

# Drawing Survival Curves Using ggplot2
# https://rpkgs.datanovia.com/survminer/reference/ggsurvplot.html

mydata %>%
  finalfit::surv_plot(.data = .,
                      dependent = "Surv(OverallTime, Outcome)",
                      explanatory = "LVI",
                      xlab='Time (months)',
                      pval=TRUE,
                      legend = 'none',
                      break.time.by = 12,
                      xlim = c(0,60)
                      # legend.labs = c('a','b')
                      )

4.3.2 Univariate Cox-Regression

library(finalfit)
library(survival)
explanatoryUni <- "LVI"
dependentUni <- "Surv(OverallTime, Outcome)"

tUni <- mydata %>% finalfit::finalfit(dependentUni, explanatoryUni)

knitr::kable(tUni, row.names = FALSE, align = c("l", "l", "r", "r", "r", "r"))
Dependent: Surv(OverallTime, Outcome) all HR (univariable) HR (multivariable)
LVI Absent 148 (100.0) - -
Present 102 (100.0) 1.45 (1.06-1.98, p=0.021) 1.45 (1.06-1.98, p=0.021)
tUni_df <- tibble::as_tibble(tUni, .name_repair = "minimal") %>% janitor::clean_names()

tUni_df_descr <- paste0("When ", tUni_df$dependent_surv_overall_time_outcome[1], 
    " is ", tUni_df$x[2], ", there is ", tUni_df$hr_univariable[2], " times risk than ", 
    "when ", tUni_df$dependent_surv_overall_time_outcome[1], " is ", tUni_df$x[1], 
    ".")

When LVI is Present, there is 1.45 (1.06-1.98, p=0.021) times risk than when LVI is Absent.

4.3.3 Kaplan-Meier Median Survival

km_fit <- survfit(Surv(OverallTime, Outcome) ~ LVI, data = mydata)
km_fit
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

   3 observations deleted due to missingness 
              n events median 0.95LCL 0.95UCL
LVI=Absent  146    100   19.7    14.1    27.1
LVI=Present 101     69   10.5     9.3    12.8
plot(km_fit)

# summary(km_fit)
km_fit_median_df <- summary(km_fit)
km_fit_median_df <- as.data.frame(km_fit_median_df$table) %>% janitor::clean_names() %>% 
    tibble::rownames_to_column()
km_fit_median_definition <- km_fit_median_df %>% dplyr::mutate(description = glue::glue("When {rowname}, median survival is {median} [{x0_95lcl} - {x0_95ucl}, 95% CI] months.")) %>% 
    dplyr::select(description) %>% dplyr::pull()

When LVI=Absent, median survival is 19.7 [14.1 - 27.1, 95% CI] months., When LVI=Present, median survival is 10.5 [9.3 - 12.8, 95% CI] months.

4.3.4 1-3-5-yr survival

summary(km_fit, times = c(12, 36, 60))
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

3 observations deleted due to missingness 
                LVI=Absent 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   12     71      52    0.612  0.0426        0.534        0.701
   36     19      38    0.235  0.0424        0.165        0.334

                LVI=Present 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   12     27      52    0.391  0.0544       0.2978        0.514
   36      5      15    0.120  0.0436       0.0593        0.245
km_fit_summary <- summary(km_fit, times = c(12, 36, 60))

km_fit_df <- as.data.frame(km_fit_summary[c("strata", "time", "n.risk", "n.event", 
    "surv", "std.err", "lower", "upper")])
km_fit_definition <- km_fit_df %>% dplyr::mutate(description = glue::glue("When {strata}, {time} month survival is {scales::percent(surv)} [{scales::percent(lower)}-{scales::percent(upper)}, 95% CI].")) %>% 
    dplyr::select(description) %>% dplyr::pull()

When LVI=Absent, 12 month survival is 61% [53%-70.1%, 95% CI]., When LVI=Absent, 36 month survival is 23% [16%-33.4%, 95% CI]., When LVI=Present, 12 month survival is 39% [30%-51.4%, 95% CI]., When LVI=Present, 36 month survival is 12% [6%-24.5%, 95% CI].

source(here::here("R", "gc_survival.R"))

4.3.5 Survival Analysis LVI

Kaplan-Meier Plot Log-Rank Test

library(survival)
library(survminer)
library(finalfit)

mydata %>%
  finalfit::surv_plot('Surv(OverallTime, Outcome)', 'LVI', 
  xlab='Time (months)', pval=TRUE, legend = 'none',
    break.time.by = 12, xlim = c(0,60)

# legend.labs = c('a','b')

)

Univariate Cox-Regression

explanatoryUni <- "LVI"
dependentUni <- "Surv(OverallTime, Outcome)"
tUni <- mydata %>% finalfit(dependentUni, explanatoryUni)

knitr::kable(tUni, row.names = FALSE, align = c("l", "l", "r", "r", "r", "r"))
Dependent: Surv(OverallTime, Outcome) all HR (univariable) HR (multivariable)
LVI Absent 148 (100.0) - -
Present 102 (100.0) 1.45 (1.06-1.98, p=0.021) 1.45 (1.06-1.98, p=0.021)

Univariate Cox-Regression Summary

tUni_df <- tibble::as_tibble(tUni, .name_repair = "minimal") %>% janitor::clean_names(dat = ., 
    case = "snake")


n_level <- dim(tUni_df)[1]

tUni_df_descr <- function(n) {
    paste0("When ", tUni_df$dependent_surv_overall_time_outcome[1], " is ", tUni_df$x[n + 
        1], ", there is ", tUni_df$hr_univariable[n + 1], " times risk than ", "when ", 
        tUni_df$dependent_surv_overall_time_outcome[1], " is ", tUni_df$x[1], ".")
    
}



results5 <- purrr::map(.x = c(2:n_level - 1), .f = tUni_df_descr)

print(unlist(results5))
[1] "When LVI is Present, there is 1.45 (1.06-1.98, p=0.021) times risk than when LVI is Absent."

Median Survival

km_fit <- survfit(Surv(OverallTime, Outcome) ~ LVI, data = mydata)
km_fit
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

   3 observations deleted due to missingness 
              n events median 0.95LCL 0.95UCL
LVI=Absent  146    100   19.7    14.1    27.1
LVI=Present 101     69   10.5     9.3    12.8
km_fit_median_df <- summary(km_fit)
km_fit_median_df <- as.data.frame(km_fit_median_df$table) %>% janitor::clean_names(dat = ., 
    case = "snake") %>% tibble::rownames_to_column(.data = ., var = "LVI")



km_fit_median_definition <- km_fit_median_df %>% dplyr::mutate(description = glue::glue("When, LVI, {LVI}, median survival is {median} [{x0_95lcl} - {x0_95ucl}, 95% CI] months.")) %>% 
    dplyr::mutate(description = gsub(pattern = "thefactor=", replacement = " is ", 
        x = description)) %>% dplyr::select(description) %>% dplyr::pull()

km_fit_median_definition
When, LVI, LVI=Absent, median survival is 19.7 [14.1 - 27.1, 95% CI] months.
When, LVI, LVI=Present, median survival is 10.5 [9.3 - 12.8, 95% CI] months.

1-3-5-yr survival

summary(km_fit, times = c(12, 36, 60))
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

3 observations deleted due to missingness 
                LVI=Absent 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   12     71      52    0.612  0.0426        0.534        0.701
   36     19      38    0.235  0.0424        0.165        0.334

                LVI=Present 
 time n.risk n.event survival std.err lower 95% CI upper 95% CI
   12     27      52    0.391  0.0544       0.2978        0.514
   36      5      15    0.120  0.0436       0.0593        0.245
km_fit_summary <- summary(km_fit, times = c(12, 36, 60))

km_fit_df <- as.data.frame(km_fit_summary[c("strata", "time", "n.risk", "n.event", 
    "surv", "std.err", "lower", "upper")])

km_fit_df
       strata time n.risk n.event      surv    std.err      lower     upper
1  LVI=Absent   12     71      52 0.6115055 0.04257648 0.53350053 0.7009157
2  LVI=Absent   36     19      38 0.2347686 0.04235846 0.16483932 0.3343638
3 LVI=Present   12     27      52 0.3911397 0.05442593 0.29777603 0.5137763
4 LVI=Present   36      5      15 0.1204428 0.04355881 0.05928425 0.2446936
km_fit_definition <- km_fit_df %>% dplyr::mutate(description = glue::glue("When {strata}, {time} month survival is {scales::percent(surv)} [{scales::percent(lower)}-{scales::percent(upper)}, 95% CI].")) %>% 
    dplyr::select(description) %>% dplyr::pull()

km_fit_definition
When LVI=Absent, 12 month survival is 61% [53%-70.1%, 95% CI].
When LVI=Absent, 36 month survival is 23% [16%-33.4%, 95% CI].
When LVI=Present, 12 month survival is 39% [30%-51.4%, 95% CI].
When LVI=Present, 36 month survival is 12% [6%-24.5%, 95% CI].
summary(km_fit)$table
            records n.max n.start events   *rmean *se(rmean) median 0.95LCL
LVI=Absent      146   146     146    100 24.32960   1.653307   19.7    14.1
LVI=Present     101   101     101     69 18.16069   1.840202   10.5     9.3
            0.95UCL
LVI=Absent     27.1
LVI=Present    12.8
km_fit_median_df <- summary(km_fit)
results1html <- as.data.frame(km_fit_median_df$table) %>% janitor::clean_names(dat = ., 
    case = "snake") %>% tibble::rownames_to_column(.data = ., var = "LVI")

results1html[, 1] <- gsub(pattern = "thefactor=", replacement = "", x = results1html[, 
    1])

knitr::kable(results1html, row.names = FALSE, align = c("l", rep("r", 9)), format = "html", 
    digits = 1)
LVI records n_max n_start events rmean se_rmean median x0_95lcl x0_95ucl
LVI=Absent 146 146 146 100 24.3 1.7 19.7 14.1 27.1
LVI=Present 101 101 101 69 18.2 1.8 10.5 9.3 12.8

Pairwise Comparisons

4.3.6 Pairwise comparison

dependentKM <- "Surv(OverallTime, Outcome)"
explanatoryKM <- "TStage"

mydata %>%
  finalfit::surv_plot(.data = .,
                      dependent = dependentKM,
                      explanatory = explanatoryKM,
                      xlab='Time (months)',
                      pval=TRUE,
                      legend = 'none',
                      break.time.by = 12,
                      xlim = c(0,60)
                      # legend.labs = c('a','b')
                      )

km_fit
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

   3 observations deleted due to missingness 
              n events median 0.95LCL 0.95UCL
LVI=Absent  146    100   19.7    14.1    27.1
LVI=Present 101     69   10.5     9.3    12.8
print(km_fit, 
      scale=1,
      digits = max(options()$digits - 4,3),
      print.rmean=getOption("survfit.print.rmean"),
      rmean = getOption('survfit.rmean'),
      print.median=getOption("survfit.print.median"),
      median = getOption('survfit.median')
      
      )
Call: survfit(formula = Surv(OverallTime, Outcome) ~ LVI, data = mydata)

   3 observations deleted due to missingness 
              n events median 0.95LCL 0.95UCL
LVI=Absent  146    100   19.7    14.1    27.1
LVI=Present 101     69   10.5     9.3    12.8

4.3.7 Multivariate Analysis Survival



5 Discussion

  • Interpret the results in context of the working hypothesis elaborated in the introduction and other relevant studies; include a discussion of limitations of the study.

  • Discuss potential clinical applications and implications for future research

References

Knijn, N., F. Simmer, and I. D. Nagtegaal. 2015. “Recommendations for Reporting Histopathology Studies: A Proposal.” Virchows Archiv 466 (6): 611–15. https://doi.org/10.1007/s00428-015-1762-3.

Schmidt, Robert L., Deborah J. Chute, Jorie M. Colbert-Getz, Adolfo Firpo-Betancourt, Daniel S. James, Julie K. Karp, Douglas C. Miller, et al. 2017. “Statistical Literacy Among Academic Pathologists: A Survey Study to Gauge Knowledge of Frequently Used Statistical Tests Among Trainees and Faculty.” Archives of Pathology & Laboratory Medicine 141 (2): 279–87. https://doi.org/10.5858/arpa.2016-0200-OA.


  1. From Table 1: Proposed items for reporting histopathology studies. Recommendations for reporting histopathology studies: a proposal Virchows Arch (2015) 466:611–615 DOI 10.1007/s00428-015-1762-3 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4460276/↩︎

  2. From Table 1: Proposed items for reporting histopathology studies. Recommendations for reporting histopathology studies: a proposal Virchows Arch (2015) 466:611–615 DOI 10.1007/s00428-015-1762-3 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4460276/↩︎

  3. See childRmd/_01header.Rmd file for other general settings↩︎

  4. Change echo = FALSE to hide codes after knitting.↩︎

  5. See childRmd/_02fakeData.Rmd file for other codes↩︎

  6. Synthea The validity of synthetic clinical data: a validation study of a leading synthetic data generator (Synthea) using clinical quality measures. BMC Med Inform Decis Mak 19, 44 (2019) doi:10.1186/s12911-019-0793-0↩︎

  7. https://bmcmedinformdecismak.biomedcentral.com/articles/10.1186/s12911-019-0793-0↩︎

  8. Synthetic Patient Generation↩︎

  9. Basic Setup and Running↩︎

  10. intelligent patient data generator (iPDG)↩︎

  11. https://medium.com/free-code-camp/how-our-test-data-generator-makes-fake-data-look-real-ace01c5bde4a↩︎

  12. https://forums.librehealth.io/t/demo-data-generation/203↩︎

  13. https://mihin.org/services/patient-generator/↩︎

  14. lung, cancer, breast datası ile birleştir↩︎

  15. See childRmd/_03importData.Rmd file for other codes↩︎

  16. See childRmd/_04briefSummary.Rmd file for other codes↩︎

  17. https://www.hhs.gov/hipaa/index.html↩︎

  18. Kişisel verilerin kaydedilmesi ve kişisel verileri hukuka aykırı olarak verme veya ele geçirme Türk Ceza Kanunu’nun 135. ve 136. maddesi kapsamında bizim hukuk sistemimizde suç olarak tanımlanmıştır. Kişisel verilerin kaydedilmesi suçunun cezası 1 ila 3 yıl hapis cezasıdır. Suçun nitelikli hali ise, kamu görevlisi tarafından görevin verdiği yetkinin kötüye kullanılarak veya belirli bir meslek veya sanatın sağladığı kolaylıktan yararlanılarak işlenmesidir ki bu durumda suçun cezası 1.5 ile 4.5 yıl hapis cezası olacaktır.↩︎

  19. See childRmd/_06variableTypes.Rmd file for other codes↩︎

  20. See childRmd/_07overView.Rmd file for other codes↩︎

  21. Statistical Literacy Among Academic Pathologists: A Survey Study to Gauge Knowledge of Frequently Used Statistical Tests Among Trainees and Faculty. Archives of Pathology & Laboratory Medicine: February 2017, Vol. 141, No. 2, pp. 279-287. https://doi.org/10.5858/arpa.2016-0200-OA↩︎

  22. From Table 1: Proposed items for reporting histopathology studies. Recommendations for reporting histopathology studies: a proposal Virchows Arch (2015) 466:611–615 DOI 10.1007/s00428-015-1762-3 https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4460276/↩︎

  23. See childRmd/_11descriptives.Rmd file for other codes↩︎

  24. See childRmd/_12crossTables.Rmd file for other codes↩︎

  25. See childRmd/_18survival.Rmd file for other codes, and childRmd/_19shinySurvival.Rmd for shiny application↩︎

  26. JAMA retraction after miscoding – new Finalfit function to check recoding↩︎

  27. See childRmd/_23footer.Rmd file for other codes↩︎

  28. Smith AM, Katz DS, Niemeyer KE, FORCE11 Software Citation Working Group. (2016) Software Citation Principles. PeerJ Computer Science 2:e86. DOI: 10.7717/peerj-cs.86 https://www.force11.org/software-citation-principles↩︎

 

A work by Serdar Balci

drserdarbalci@gmail.com